{% extends "base.html" %}
{% load promgen %}
{% load tz %}
{% block content %}

{% breadcrumb label="Alerts" %}

<form class="navbar-form navbar-left" action="/alert">
    <div class="form-group">
        <input name="search" type="text" value="{{ request.GET.search }}" class="form-control" placeholder="Service, Project, Job">
        <button type="submit" class="btn btn-default">Search</button>
    </div>
</form>

<table class="table table-sm">
    <tr>
        <th>Created</th>
        <th>Alertname</th>
        <th>Datasource</th>
        <th>Service</th>
        <th>Project</th>
        <th>Job</th>
        <th><a href="?noSent=1">Sent</a></th>
        <th><a href="?sentError=1">Error</a></th>
    </tr>
    {% for alert in alert_list %}
    {% ifchanged alert.created|date %}
    <tr class="table-secondary">
        <th colspan="8" v-pre>{{ alert.created|date }}</th>
    </tr>
    {% endifchanged %}
    <tr>
        <td><a href="{{alert.get_absolute_url}}" v-pre>{{ alert.created|timezone:TIMEZONE }}</a></td>
        <td><a href="?alertname={{alert.json.commonLabels.alertname}}" v-pre>{{alert.json.commonLabels.alertname}}</a></td>
        <td v-pre>{{alert.json.commonLabels.datasource}}</td>
        <td><a href="?service={{alert.json.commonLabels.service}}" v-pre>{{alert.json.commonLabels.service}}</a></td>
        <td><a href="?project={{alert.json.commonLabels.project}}" v-pre>{{alert.json.commonLabels.project}}</a></td>
        <td><a href="?job={{alert.json.commonLabels.job}}" v-pre>{{alert.json.commonLabels.job}}</a></td>
        <td {% if alert.sent_count == 0 %}class="warning" {% endif %}>{{alert.sent_count}}</td>
        <td {% if alert.error_count %}class="danger" {% endif %}>{{alert.error_count}}</td>
    </tr>
    {% endfor %}
</table>

{% include 'promgen/pagination_short.html' %}

{% endblock %}
